from rest_framework import serializers

from apps.app_talk.models import Mood, Talk


class MoodsSerializer(serializers.ModelSerializer):
    talk_num = serializers.SerializerMethodField()

    class Meta:
        model = Mood
        fields = ('id', 'name', 'talk_num')

    def get_talk_num(self, obj):
        return obj.talks.count()


class TalksSerializer(serializers.ModelSerializer):
    mood = MoodsSerializer()

    class Meta:
        model = Talk
        fields = ('id', 'content', 'mood', 'pub_time')
